﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PokerClient.Connection.CommandFactories;
using PokerClient.Connection.Interfaces;
using PokerClient.VisualDisp;

namespace PokerClient.Connection.CommandHandlers
{
	class CommandHandler : IHandle
	{
		Handlerfact factory;
		String commands,answer = "null";
		MainWindow window;
		Lobby lobby;
		Table table;
		IHandle handler;
		private Client myClient;

		public CommandHandler(MainWindow window,Client myClient)
		{
			factory = new Handlerfact();
			this.window = window;
			this.myClient = myClient;
		}

		public void assignLobby(Lobby lobby)
		{
			this.lobby = lobby;
		}

		public void assiginTable(Table table)
		{
			this.table = table;
		}
		public string work()
		{
			return answer;
		}

		public void assignCommand(string commands)
		{
			this.commands = commands;
		}

		public void analyze()
		{
			handler = factory.getHandler(commands,window,lobby,table,myClient);
			if (handler != null)
			{
				handler.assignCommand(commands);
				answer = handler.work();
				 handler.analyze();
			}
			
		}
	}
}
